﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NutriLeaf.Web.Core.Food
{
    public class FoodTime:IFoodTime
    {
        public void AddFoodTime(int foodId, TimeSpan startTime, TimeSpan endTime, ref Model.NutriLeafDBEntities context)
        {
            Model.FoodTime tfood = new Model.FoodTime();
            tfood.FoodID = foodId;
            tfood.TimeStart = startTime;
            tfood.TimeEnd = endTime;
            context.FoodTimes.AddObject(tfood);
            context.SaveChanges();
        }

        public void AddFoodTime(Model.FoodTime foodTime, ref Model.NutriLeafDBEntities context)
        {
            context.FoodTimes.AddObject(foodTime);
            context.SaveChanges();
        }

        public void RemoveFoodTime(int foodTime, ref Model.NutriLeafDBEntities context)
        {

            if(context.FoodTimes.Where(p=>p.FoodTimeID==foodTime).Count()!=0){
                context.FoodTimes.DeleteObject(context.FoodTimes.Where(p => p.FoodTimeID == foodTime).First());
                context.SaveChanges();
            }
        }

        public List<Model.FoodTime> GetFoodTime(int foodId, ref Model.NutriLeafDBEntities context)
        {
            return context.FoodTimes.Where(p => p.FoodID == foodId).ToList();
        }
    }
}